import type { VulnerabilityState } from 'types/vulnState.proto';

/** ===== Based on v2/vulnerability.proto ===== */

export type EmbeddedVulnerability = {
    cve: string;
    advisory: Advisory;
    cvss: number;
    summary: string;
    link: string;
    fixedBy?: string;
    cvssV3: CVSSV3;
    publishedOn: string; // ISO 8601 date string;
    lastModified: string; // ISO 8601 date string;
    vulnerabilityType: VulnerabilityType;
    vulnerabilityTypes: VulnerabilityType[];
    suppressed: boolean;
    suppressActivation: string; // ISO 8601 date string;
    suppressExpiry: string; // ISO 8601 date string;
    firstSystemOccurrence: string; // ISO 8601 date string;
    firstImageOccurrence: string; // ISO 8601 date string;
    severity: VulnerabilitySeverity;
    state: VulnerabilityState;
    cvssMetrics: CVSSScore[];
    nvdCvss: number;
    epss: EPSS;
};

type VulnerabilityType =
    | 'UNKNOWN_VULNERABILITY'
    | 'IMAGE_VULNERABILITY'
    | 'K8S_VULNERABILITY'
    | 'ISTIO_VULNERABILITY'
    | 'NODE_VULNERABILITY'
    | 'OPENSHIFT_VULNERABILITY'
    | 'VIRTUAL_MACHINE_VULNERABILITY';

type VulnerabilitySeverity =
    | 'UNKNOWN_VULNERABILITY_SEVERITY'
    | 'LOW_VULNERABILITY_SEVERITY'
    | 'MODERATE_VULNERABILITY_SEVERITY'
    | 'IMPORTANT_VULNERABILITY_SEVERITY'
    | 'CRITICAL_VULNERABILITY_SEVERITY';

type EPSS = {
    epssProbability: number;
    epssPercentile: number;
};

export type Advisory = {
    name: string;
    link: string;
};

type CVSSScore = {
    source: CVSSSource;
    url: string;
    cvssv3: CVSSV3;
};

type CVSSSource = 'SOURCE_UNKNOWN' | 'SOURCE_RED_HAT' | 'SOURCE_OSV' | 'SOURCE_NVD';

type CVSSV3 = {
    vector: string;
    exploitabilityScore: number;
    impactScore: number;
    attackVector: CVSSV3AttackVector;
    attackComplexity: CVSSV3Complexity;
    privilegesRequired: CVSSV3Privileges;
    userInteraction: CVSSV3UserInteraction;
    scope: CVSSV3Scope;
    confidentiality: CVSSV3Impact;
    integrity: CVSSV3Impact;
    availability: CVSSV3Impact;
    score: number;
    severity: CVSSV3Severity;
};

type CVSSV3Impact = 'IMPACT_NONE' | 'IMPACT_LOW' | 'IMPACT_HIGH';
type CVSSV3AttackVector = 'ATTACK_LOCAL' | 'ATTACK_ADJACENT' | 'ATTACK_NETWORK' | 'ATTACK_PHYSICAL';
type CVSSV3Complexity = 'COMPLEXITY_LOW' | 'COMPLEXITY_HIGH';
type CVSSV3Privileges = 'PRIVILEGE_NONE' | 'PRIVILEGE_LOW' | 'PRIVILEGE_HIGH';
type CVSSV3UserInteraction = 'UI_NONE' | 'UI_REQUIRED';
type CVSSV3Scope = 'UNCHANGED' | 'CHANGED';
export type CVSSV3Severity = 'UNKNOWN' | 'NONE' | 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
